package cn.classyex.business.hr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import cn.classyex.business.hr.domain.Resume;
import cn.classyex.business.hr.service.IResumeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 简历管理Controller
 * 
 * @author yex
 * @date 2021-05-05
 */
@Controller
@RequestMapping("/hr/resume")
public class ResumeController extends BaseController
{
    private String prefix = "hr/resume";

    @Autowired
    private IResumeService resumeService;

    @RequiresPermissions("hr:resume:view")
    @GetMapping()
    public String resume()
    {
        return prefix + "/resume";
    }

    /**
     * 查询简历管理列表
     */
    @RequiresPermissions("hr:resume:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Resume resume)
    {
        startPage();
        List<Resume> list = resumeService.selectResumeList(resume);
        return getDataTable(list);
    }

    /**
     * 导出简历管理列表
     */
    @RequiresPermissions("hr:resume:export")
    @Log(title = "简历管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Resume resume)
    {
        List<Resume> list = resumeService.selectResumeList(resume);
        ExcelUtil<Resume> util = new ExcelUtil<Resume>(Resume.class);
        return util.exportExcel(list, "简历管理数据");
    }

    /**
     * 新增简历管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存简历管理
     */
    @RequiresPermissions("hr:resume:add")
    @Log(title = "简历管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Resume resume)
    {
        return toAjax(resumeService.insertResume(resume));
    }

    /**
     * 修改简历管理
     */
    @GetMapping("/edit/{resumeId}")
    public String edit(@PathVariable("resumeId") Long resumeId, ModelMap mmap)
    {
        Resume resume = resumeService.selectResumeById(resumeId);
        mmap.put("resume", resume);
        return prefix + "/edit";
    }

    /**
     * 修改保存简历管理
     */
    @RequiresPermissions("hr:resume:edit")
    @Log(title = "简历管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Resume resume)
    {
        return toAjax(resumeService.updateResume(resume));
    }

    /**
     * 删除简历管理
     */
    @RequiresPermissions("hr:resume:remove")
    @Log(title = "简历管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(resumeService.deleteResumeByIds(ids));
    }
}
